function onBeforeDestroyPage()
{
	// 用户已经注销则不继续执行
	if(parent.$logoutflag != null && parent.$logoutflag == true)
		return false;
}
/**
 * 查询模板调用此函数,将查询条件传给该页面
 */
function saveQryCondition(qryObj,map,otherMap,flag)
{
 	window.qryConditionObj = qryObj;
 	window.map = map;
 	window.otherMap =otherMap; 
 	window.isFromQuery = flag; 
}
/*查询后表头显示字段*/
function saveMap(map,otherMap){
 	window.map = map;
 	window.otherMap =otherMap; 
}

/*
 * 报销打印   
 */
function doPrint(){
	var headDs = getDataset('headDataset');
	var bodyDs = getDataset('bodyDataset');
	if(!bodyDs.isDsInitialized()){
		showMessageDialog(webbx_trans('yer_selectrow'));
			return;
	}
	var dsArray = new Array;
	var rowArray = new Array;
	dsArray.push(headDs);
	dsArray.push(bodyDs);
	rowArray.push(null);
	rowArray.push(null);

	var paramStr = createCommonProcessXMLParameter(dsArray, rowArray);
	var args = new Array;
	args.push(paramStr);
	
	if(window.visibleMap != null && window.visibleMap.keySet().length > 0){
		var valueStr = "";
		var keyStr = "";
		var size = visibleMap.keySet().length;
		for(var i = 0; i < size; i ++){
			var key = visibleMap.keySet()[i];
			if(key == "qryobj0")
				key = "qryobjname0";
			else if(key == "qryobj1")
				key = "qryobjname1";
			else if(key == "qryobj2")
				key = "qryobjname2";
			else if(key == "qryobj3")
				key = "qryobjname3";
			keyStr += key;
			var value = bodyDs.metadata[bodyDs.nameToIndex(key)].value;
			valueStr += value;
			if(i != size -1){
				keyStr += ",";
				valueStr += ",";
			}
		}
		paramStr += "&extendkeys=" + keyStr + "&extendvalues=" + encodeURIComponent(valueStr);
	}
	var cmd = new CommonCommand('doPrint');
	cmd.setAsync(true);
	cmd.setParameter(paramStr);
	cmd.setReturnFunc(printReturnFun);
	cmd.setReturnArgs(args);
	cmd.setCallObj(this);
	cmd.exec();
	showProgressDialog(webbx_trans('yer_wait'));
}

/**
 *	打印模版的ajax回掉处理函数
 *	@private
 */
function printReturnFun(result, args, success)
{
	if(success) 
	{ 
		var filePath = result[0];
		// 如果成立,说明仅有唯一的打印模版
		if(filePath != null && filePath != "" && filePath != "NEEDSELECT")
			window.open(getRootPath() + "/printfile.pdf?filePath=" + filePath, "xxx", "toolbar=no,menubar=yes,scrollbar=yes,resizable=yes,location=no,status=no,fullscreen=no");
		else if(filePath == "NEEDSELECT")
			showPrintDlg(result, args[0]);
	}
	hideProgressDialog();
};

/**
 *	显示打印对话框
 */
function showPrintDlg(selectResult, paramStr)
{
	if(window["$print_Template_ids_select_dlg"] == null)
	{
		var dlg = new ModalDialogComp("print_Template_ids_select_dlg", webbx_trans('yer_chooseprinttemplate'), 0, 0, 300, 200);
		var labelComp = new LabelComp(dlg, "print_Template_ids_select_dlg_label", 40, 32, webbx_trans('yer_choosetemplate'), "absolute");
		var idsComboComp = new ComboComp(dlg, "print_Template_ids_select_dlg_printIdsCombo", 100, 30, 150, "absolute");
		var okBtn = new ButtonComp(dlg, "print_Template_ids_select_dlg_OkBtn", 70, 120, 70, 20, webbx_trans('yer_confirm'), webbx_trans('yer_confirm'), null, "absolute");
		var cancelBtn = new ButtonComp(dlg, "print_Template_ids_select_dlg_CancelBtn", 160, 120, 70, 20, webbx_trans('yer_cancel'), webbx_trans('yer_cancel'), null, "absolute");
		this.showPrintDlg.comboComp = idsComboComp;
		window["$print_Template_ids_select_dlg"] = dlg;
		
		var oThis = this;
		okBtn.onclick = function(e)
		{
			var selectedValue = idsComboComp.getValue();
			if(selectedValue == null)
			{
				showMessageDialog(webbx_trans('yer_chooseusedprinttemplate'));
				return;	
			}
			
//			var args = new Array;
//			args.push(paramStr);
			// 再次向后台发送ajax请求,此时传递用户选择的模版id
			
			var cmd = new CommonCommand('doPrint');
			cmd.setAsync(true);
			cmd.setParameter(window["$print_Template_ids_select_dlg"].nowParamStr + "&selectedTemplateId=" + selectedValue);
			cmd.setReturnFunc(oThis.printReturnFun);
			cmd.setCallObj(this);
			cmd.exec();
	
			processCommonLogic(window["$print_Template_ids_select_dlg"].nowParamStr + "&selectedTemplateId=" + selectedValue, "doPrint", oThis.printReturnFun, null, true, null, null, this);
			showProgressDialog(webbx_trans('yer_wait'));
			dlg.hide();
		};
		
		cancelBtn.onclick = function(e)
		{
			dlg.hide();
		};
	}
	
	window["$print_Template_ids_select_dlg"].nowParamStr = paramStr;
	window["$print_Template_ids_select_dlg"].show();
	var combo = this.showPrintDlg.comboComp;
	combo.clearOptions();
	var keyValues = null;
	for(var i = 1, count = selectResult.length; i < count; i++)
	{
		keyValues = selectResult[i];
		keyValues = keyValues.split(";");
		if(i == 1)
			combo.createOption(keyValues[1], keyValues[0], null, true);	
		else
			combo.createOption(keyValues[1], keyValues[0]);
	}
};

window.visibleMap = null; 	
/**
 * showElementIds: 数组,5个查询对象中显示哪些 
 */
function repaintForm(visibleEleId_ValueMap,otherMap)
{
	window.visibleMap = visibleEleId_ValueMap;
	if(visibleEleId_ValueMap == null && otherMap == null)
		return;
	
	var form = getComponent("headForm");
	var formDs = getDataset("headDataset");
	var elements = form.eleArr;
	var layout = form.pLayout;
	for(var i = 0, count = elements.length; i < count; i++)
	{
		if(form.keyArr[i].startWith("qryobj"))
		{
			formDs.setValueAt(0, formDs.nameToIndex(form.keyArr[i]),null);
			if(visibleEleId_ValueMap.containsKey(form.keyArr[i]))
			{
				layout.getCompById(form.keyArr[i]).visible = true;
				elements[i].setActive(false);
				formDs.setValueAt(0, formDs.nameToIndex(form.keyArr[i]), visibleEleId_ValueMap.get(form.keyArr[i]));
			}	
			else
				elements[i].visible = false;	
		}
		if(otherMap.containsKey(form.keyArr[i])){
			/*设置 公司、帐页格式、日期*/
			formDs.setValueAt(0, formDs.nameToIndex(form.keyArr[i]), otherMap.get(form.keyArr[i]));
		}
	}

	if(layout)
	{
		layout.setForceRepaint(true);
		layout.paint();
		adjustSpliter();
	}	

	var showTypeIndex = formDs.nameToIndex("showtype");
	var booktypeIndex = formDs.nameToIndex("booktype");
	var row = formDs.getRow(0);
	window.qryObjs = visibleEleId_ValueMap.keySet();
	setGridVisibleHeaders(window.qryObjs, row.getCellValue(booktypeIndex), row.getCellValue(showTypeIndex));
}